package com.sunmouse.toollib.utils.load;

import android.text.TextUtils;

import com.sunmouse.toollib.utils.FileUtils;

import java.io.File;

/**
 * Created by leiyun on 2018/5/24.
 */
public class LoadRequest {

    private File outFile;
    private String remoteUrl;
    private long start;
    private long end;
    private long progress;
    private long length;
    private int position;
    private boolean isStop;
    private boolean isFinished;
    private boolean isLoading;


    private LoadRequest(Builder builder) {
        this.start = builder.getStart();
        this.outFile = builder.getOutFile();
        this.remoteUrl = builder.getRemoteUrl();
    }

    /**
     * build
     */
    public static class Builder {
        private File outFile;
        private String remoteUrl;
        private long start;

        public File getOutFile() {
            return outFile;
        }


        public String getRemoteUrl() {
            return remoteUrl;
        }


        public long getStart() {
            return start;
        }

        public Builder() {
        }


        public Builder(int start, File outFile, String remoteUrl) {
            this.start = start;
            this.outFile = outFile;
            this.remoteUrl = remoteUrl;
        }

        public Builder(File outFile, String remoteUrl) {
            this(0, outFile, remoteUrl);
        }

        public Builder(int start, String outFile, String remoteUrl) {
            this.start = start;
            this.outFile = FileUtils.newFile(outFile);
            this.remoteUrl = remoteUrl;
        }

        public Builder(String outFile, String remoteUrl) {
            this(0, outFile, remoteUrl);
        }

        /**
         * set out file
         */
        public Builder outFile(File outFile) {
            if (outFile == null) {
                throw new RuntimeException("Load:outFile is null");
            }
            this.outFile = outFile;
            return this;
        }

        /**
         * set out file
         */
        public Builder outFile(String outFile) {
            if (TextUtils.isEmpty(outFile)) {
                throw new RuntimeException("Load:outFile is null");
            }
            this.outFile = FileUtils.newFile(outFile);
            return this;
        }

        /**
         * set out file
         */
        public Builder remoteUrl(String remoteUrl) {
            if (TextUtils.isEmpty(remoteUrl)) {
                throw new RuntimeException("Load:remoteUrl is null");
            }
            this.remoteUrl = remoteUrl;
            return this;
        }

        /**
         * start
         */
        public Builder start(long start) {
            this.start = start;
            return this;
        }

        /**
         * build
         */
        public LoadRequest build() {
            return new LoadRequest(this);
        }

    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public boolean isFinished() {
        return isFinished;
    }

    public void setFinished(boolean finished) {
        isFinished = finished;
    }


    public boolean isLoading() {
        return isLoading;
    }

    public void setLoading(boolean loading) {
        isLoading = loading;
    }

    public long getProgress() {
        return progress;
    }

    public void setProgress(long progress) {
        this.progress = progress;
    }

    public long getLength() {
        return length;
    }

    public void setLength(long length) {
        this.length = length;
    }

    /**
     *
     */
    public File getOutFile() {
        return outFile;
    }

    public String getRemoteUrl() {
        return remoteUrl;
    }

    public long getStart() {
        return start;
    }

    public void setStart(long start) {
        this.start = start;
    }

    public long getEnd() {
        return end;
    }

    public void setEnd(long end) {
        this.end = end;
    }

    public boolean isStop() {
        return isStop;
    }

    public void setStop(boolean stop) {
        this.isStop = stop;
    }
}
